#include "stdafx.h"
#include "standard/dump.h"
#include "standard/nstring.h"
#include "standard/nfile.h"
#include "standard/stdafx.h"


int dump(mapIntStrStr mmstr)
{
    return dump(mmstr, 0);    
}
int dump(mapIntStr mstr)
{
    return dump(mstr, 0);
}

#if defined(_MSC_VER)
std::string utf8togbk(const std::string str)
{
	std::wstring wstr = UTF8ToUnicode( str );
	std::string gstr = UnicodeToANSI(wstr);

	return gstr;
}
#endif

int dump(mapIntStrStr mmstr, int flag)
{
    std::string ret;
    mapStrStr::iterator mitor;
#if defined(__GNUC__)
    ret = "Array => { \n\n";
    for (unsigned int n=0; n < mmstr.size(); n++)
    {
        ret += "    [ "+itos(n)+" ] => { \n";
        for (mitor = mmstr[n].begin(); mitor != mmstr[n].end(); mitor++)
        {
            ret += "        [ "+mitor->first+" ] => "+mitor->second+"\n";
        }
        ret += "    }\n\n";
    }
    ret += "} \n";
    
    if (flag == 0) {
        std::cout<<ret;
    }
    else {
        runlog(ret);
    }
#endif

#if defined(_MSC_VER)
	ret = "Array => { \n\n";
    for (unsigned int n=0; n < mmstr.size(); n++)
    {
        ret += utf8togbk("    [ "+itos(n)+" ] => { \n");
        for (mitor = mmstr[n].begin(); mitor != mmstr[n].end(); mitor++)
        {
            ret += utf8togbk("        [ "+mitor->first+" ] => "+mitor->second+"\n");
        }
        ret += "    }\n\n";
    }
    ret += "} \n";
    
    if (flag == 0) {
        std::cout<<ret;
    }
    else {
        runlog(ret);
    }
#endif
    
    return true;
}


int dump(mapStrStr mstr)
{
	return dump(mstr, 0);
}
int dump(mapStrStr mstr, int flag)
{
    std::string ret;
    mapStrStr::iterator mitor;
	#if defined(__GNUC__)
    ret = "Array => { \n";
    for (mitor = mstr.begin(); mitor != mstr.end(); mitor++)
    {
        ret += " ["+mitor->first+"] => \""+mitor->second+"\"\n";
    }
    ret += "} \n";
    
    if (flag == 0) {
        std::cout<<ret;
    }
    else {
        runlog(ret);
    }
  #endif

	#if defined(_MSC_VER)
	 ret = "Array => { \n";
    for (mitor = mstr.begin(); mitor != mstr.end(); mitor++)
    {
        ret += utf8togbk(" ["+mitor->first+"] => \""+mitor->second+"\"\n");
    }
    ret += "} \n";
    
    if (flag == 0) {
        std::cout<<ret;
    }
    else {
        runlog(ret);
    }
	#endif
    return true;
}

int dump(mapIntStr mstr, int flag)
{
    std::string ret;
    mapIntStr::iterator mitor;
#if defined(__GNUC__)
    ret = "Array => { \n";
    for (mitor = mstr.begin(); mitor != mstr.end(); mitor++)
    {
        ret += " [" + itos(mitor->first)+"] => \"" + mitor->second + "\"\n";
    }
    ret += "} \n";
    
    if (flag == 0) {
        std::cout<<ret;
    }
    else {
        runlog(ret);
    }
#endif
#if defined(_MSC_VER)
	ret = "Array => { \n";
    for (mitor = mstr.begin(); mitor != mstr.end(); mitor++)
    {
        ret += utf8togbk(" [" + itos(mitor->first)+"] => \"" + mitor->second + "\"\n");
    }
    ret += "} \n";
    
    if (flag == 0) {
        std::cout<<ret;
    }
    else {
        runlog(ret);
    }
#endif
    return true;
}

int dump(mapStrStrIntStr mstr)
{
    return dump(mstr, 0);
}

int dump(mapStrIntStr mstr)
{
    return dump(mstr, 0);
}



int dump(mapStrStrIntStr mstr, int flag)
{
    std::string ret;
    mapStrStrIntStr::iterator itor1;
    mapStrIntStr::iterator itor2;
    mapIntStr::iterator itor3;
#if defined(__GNUC__)
    ret = "Array => { \n";
    for (itor1 = mstr.begin(); itor1 != mstr.end(); itor1++) {    
        ret += "    ["+itor1->first+"] => Array { \n";        
        for (itor2 = (itor1->second).begin(); itor2 != (itor1->second).end(); itor2++) {
            ret +="        ["+itor2->first+"] => Array {\n";
            for (itor3=(itor2->second).begin(); itor3!=(itor2->second).end(); itor3++) {
                ret.append("            [");
                ret.append(itos(itor3->first));
                ret.append("] => ");
                ret.append(itor3->second);
                ret.append("\n");
                //ret += "            [" + itor3->first+ "] => " + itor3->second + "\n";
            }        
            ret +="        }\n";
        }
        ret +="    }\n\n";
    }
    ret +="}\n\n";
    
    if (flag == 0) {
        std::cout<<ret;
    }
    else {
        runlog(ret);
    }
#endif
#if defined(_MSC_VER)
	  ret = "Array => { \n";
    for (itor1 = mstr.begin(); itor1 != mstr.end(); itor1++) {    
        ret +=utf8togbk( "    ["+itor1->first+"] => Array { \n");        
        for (itor2 = (itor1->second).begin(); itor2 != (itor1->second).end(); itor2++) {
            ret +=utf8togbk("        ["+itor2->first+"] => Array {\n");
            for (itor3=(itor2->second).begin(); itor3!=(itor2->second).end(); itor3++) {
                ret.append("            [");
                ret.append(utf8togbk(itos(itor3->first)));
                ret.append("] => ");
                ret.append(utf8togbk(itor3->second));
                ret.append("\n");
                //ret += "            [" + itor3->first+ "] => " + itor3->second + "\n";
            }        
            ret +="        }\n";
        }
        ret +="    }\n\n";
    }
    ret +="}\n\n";
    
    if (flag == 0) {
        std::cout<<ret;
    }
    else {
        runlog(ret);
    }
#endif
    return true;
}

int dump(mapStrIntStr mstr, int flag)
{
    mapStrIntStr::iterator itor1;
    mapIntStr::iterator itor2;
    std::string ret;
#if defined(__GNUC__)
    ret = "Array => { \n";
    for (itor1 = mstr.begin(); itor1 != mstr.end(); itor1++) {
        ret += "    [" + itor1->first + "] => Array {\n";
        for (itor2=(itor1->second).begin(); itor2!=(itor1->second).end(); itor2++) {
            ret.append("        [");
            ret.append(itos(itor2->first));
            ret.append("] => ");
            ret.append(itor2->second);
            ret.append("\n");
            //ret += "        [" + itor2->first + "] => " + itor2->second + "\n";
        }        
        ret += "    }\n";
    }
    ret += "}\n\n";
    
    if (flag == 0) {
        std::cout<<ret;
    }
    else {
        runlog(ret);
    }
#endif

#if defined(_MSC_VER)
	ret = "Array => { \n";
    for (itor1 = mstr.begin(); itor1 != mstr.end(); itor1++) {
        ret += utf8togbk("    [" + itor1->first + "] => Array {\n");
        for (itor2=(itor1->second).begin(); itor2!=(itor1->second).end(); itor2++) {
            ret.append("        [");
            ret.append(utf8togbk(itos(itor2->first)));
            ret.append("] => ");
            ret.append(utf8togbk(itor2->second));
            ret.append("\n");
            //ret += "        [" + itor2->first + "] => " + itor2->second + "\n";
        }        
        ret += "    }\n";
    }
    ret += "}\n\n";
    
    if (flag == 0) {
        std::cout<<ret;
    }
    else {
        runlog(ret);
    }
#endif
    return true;
}

int dump(vectorStr vstr)
{
    return dump(vstr, 0);
}

int dump(vectorStr vstr, int flag)
{
    vectorStr::iterator vitor;
    unsigned int i;
    std::string ret;
  #if defined(__GNUC__)
    ret = "Array => { \n";
    for (i=0, vitor = vstr.begin(); vitor != vstr.end(); vitor++, i++)
    {
        ret += "  [ "+itos(i)+" ] => "+*vitor+"\n";
    }
    ret += "} \n";
    
    if (flag == 0) {
        std::cout<<ret;
    }
    else {
        runlog(ret);
    }
#endif
#if defined(_MSC_VER)
	 ret = "Array => { \n";
    for (i=0, vitor = vstr.begin(); vitor != vstr.end(); vitor++, i++)
    {
        ret += utf8togbk("  [ "+itos(i)+" ] => "+*vitor+"\n");
    }
    ret += "} \n";
    
    if (flag == 0) {
        std::cout<<ret;
    }
    else {
        runlog(ret);
    }
#endif
    return true;
}

int dump(stackConstChar sstr)
{

    std::string ret;
#if defined(__GNUC__)
    ret = "Array => { \n";
    for (int i=0; !sstr.empty(); i++)
    {
        ret.append(sstr.top());
        ret.append("\n");
        sstr.pop();
    }
    ret += "} \n";
#endif
 #if defined(_MSC_VER)
	  ret = "Array => { \n";
    for (int i=0; !sstr.empty(); i++)
    {
        ret.append(utf8togbk(sstr.top()));
        ret.append("\n");
        sstr.pop();
    }
    ret += "} \n";
#endif

    return true;
}

int dump(stackCh sstr)
{
    std::string ret;

    for (int i=0; !sstr.empty(); i++)
    {
        ret += sstr.top();
        ret.append(1, sstr.top());
        sstr.pop();
    }
    ret += "\n";

	return true;
}

const char* dump(vectorConstChar vstr)
{
    std::string s, t, ret;
    #if defined(__GNUC__)
    s.erase();
    for (unsigned int i=0; i<vstr.size(); i++)
    {
        t = vstr[i];
        s += t;
    }
    ret += s+"\n";
    return s.c_str();
#endif
#if defined(_MSC_VER)
	   s.erase();
    for (unsigned int i=0; i<vstr.size(); i++)
    {
        t =utf8togbk(vstr[i]);
        s += t;
    }
    ret += s+"\n";
    return s.c_str();
#endif
}
